﻿using Microsoft.International.Converters.PinYinConverter;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
using Wy.JiZhangSoft.Dictionaries.Dtos;

namespace Wy.JiZhangSoft.Dictionaries
{
    public class DictionaryAppService : JiZhangSoftAppService
    {
        private readonly IRepository<Dictionary> _dictionary;

        public DictionaryAppService(IRepository<Dictionary> dictionary)
        {
            this._dictionary = dictionary;
        }

        public Task Add(DictionaryAddDto item)
        {
            //ChineseChar chineseChar = new ChineseChar()
            Dictionary entity = new Dictionary(GuidGenerator.Create());
            entity = ObjectMapper.Map(item, entity);
            entity.SetCode(item.ParentCode);
            return _dictionary.InsertAsync(entity);
        }
        


        public List<DictionaryGetDto> Get(string parentCode)
        {
            var entites = _dictionary.Where(x => x.Code.Contains(parentCode)).OrderBy(x=>x.SerialNumber).ToList();
            var dtos = ObjectMapper.Map<List<Dictionary>, List<DictionaryGetDto>>(entites);
            return dtos;
        }
    }
}
